#region License
// CoreViewModelExtensionsTest.cs
// 
// Copyright (c) 2012 Xoqal.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
// http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#endregion

using System;
using System.ComponentModel;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Xoqal.Core.Extensions;

namespace Xoqal.Tests.CoreTests
{
    [TestClass]
    public class CoreViewModelExtensionsTest
    {
        [TestMethod]
        public void RaiseProeprtyChangedExtensionWorksCorrectly()
        {
            NotifyTestObject ob = new NotifyTestObject();
            ob.TestProperty = 10;
            Assert.AreEqual("TestProperty", ob.LastChangedPropertyName);
        }

        // TODO: Use mocking frameworks
        public class NotifyTestObject : Xoqal.Core.Models.INotificationObject
        {
            private int testProperty;

            /// <summary>
            /// Occurs when property changed.
            /// </summary>
            public event PropertyChangedEventHandler PropertyChanged;

            /// <summary>
            /// Gets or sets the last name of the changed property.
            /// </summary>
            /// <value>
            /// The last name of the changed property.
            /// </value>
            public string LastChangedPropertyName { get; set; }

            /// <summary>
            /// Raises the <see cref="INotifyPropertyChanged.PropertyChanged" /> event.
            /// </summary>
            /// <param name="propertyName"></param>
            public void RaisePropertyChanged(string propertyName)
            {
                this.LastChangedPropertyName = propertyName;
            }

            /// <summary>
            /// Gets or sets the test property.
            /// </summary>
            /// <value>
            /// The test property.
            /// </value>
            public int TestProperty
            {
                get 
                { 
                    return this.testProperty; 
                }

                set 
                { 
                    this.testProperty = value;
                    this.RaisePropertyChanged(() => this.TestProperty);
                }
            }
        }
    }
}
